/**
 * FileFind - ftp/shares indexing and search php engine
 * Module: agent-java
 * Description: Agent written in java language
 * Copyright (c) 2003-2010 Rage Steel, www.gt2.ru
 * ----------------------------------------------
 * $Id$
 */
package ru.ffind.agent.net;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 *
 * Miscellaneous networking tools
 *
 * @author Rage Steel
 */
public class NetTools {

	private NetTools() {
        // Private constuctor to disallow creating of instance
	}
	
	public static final String HOSTNAME;
	public static final int IP_ADDRESS;
	
	static {
		InetAddress localhost;
		try {
			localhost = InetAddress.getLocalHost();
		} catch (UnknownHostException e) {
			throw new IllegalArgumentException("Unable to get information about localhost", e);
		}
		HOSTNAME = localhost.getHostName();
		IP_ADDRESS = inetAton(localhost);
	}
	
	/**
	 * 
	 * Address to integer number, like MySQL INET_ATON
	 * @return
	 */
	public static int inetAton(InetAddress inetAddress) {
		return inetAton(inetAddress.getAddress());
	}
	
	public static int inetAton(byte[] bytes) {
		return (bytes[0] << 24) + (bytes[1] << 16) + (bytes[2] << 8) + bytes[3];
	}
}
